package top.yjp.jtf.plugin;

import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Map;

/**
 * Excel语法高亮颜色设置页面
 */
public class ExcelColorSettingsPage implements ColorSettingsPage {
    private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{
            new AttributesDescriptor("Entity Class", ExcelSyntaxHighlighter.ENTITY_CLASS),
            new AttributesDescriptor("Property", ExcelSyntaxHighlighter.PROPERTY),
            new AttributesDescriptor("Operator", ExcelSyntaxHighlighter.OPERATOR),
            new AttributesDescriptor("Logic Operator", ExcelSyntaxHighlighter.LOGIC_OPERATOR),
            new AttributesDescriptor("String", ExcelSyntaxHighlighter.STRING),
            new AttributesDescriptor("Number", ExcelSyntaxHighlighter.NUMBER),
            new AttributesDescriptor("Keyword", ExcelSyntaxHighlighter.KEYWORD),
            new AttributesDescriptor("Comment", ExcelSyntaxHighlighter.COMMENT),
            new AttributesDescriptor("Bad Character", ExcelSyntaxHighlighter.BAD_CHARACTER)
    };

    @Nullable
    @Override
    public Icon getIcon() {
        return ExcelFileType.INSTANCE.getIcon();
    }

    @NotNull
    @Override
    public SyntaxHighlighter getHighlighter() {
        return new ExcelSyntaxHighlighter();
    }

    @NotNull
    @Override
    public String getDemoText() {
        return "// 这是一个Excel单元格内容的示例\n" +
               "// JSON示例\n" +
               "{\n" +
               "  \"name\": \"张三\",\n" +
               "  \"age\": 30,\n" +
               "  \"isActive\": true\n" +
               "}\n\n" +
               "// 断言语法示例\n" +
               "Employee.name==\"于先生\"\n" +
               "Customer.age>18\n" +
               "Order.status!=\"已取消\"\n" +
               "Product.price>=100.50\n" +
               "if (User.role==\"admin\") {\n" +
               "  return true;\n" +
               "}";
    }

    @Nullable
    @Override
    public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
        return null;
    }

    @NotNull
    @Override
    public AttributesDescriptor[] getAttributeDescriptors() {
        return DESCRIPTORS;
    }

    @NotNull
    @Override
    public ColorDescriptor[] getColorDescriptors() {
        return ColorDescriptor.EMPTY_ARRAY;
    }

    @NotNull
    @Override
    public String getDisplayName() {
        return "Excel";
    }
}